import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:${USER}
 * Date:${YEAR}-${MONTH}-${DAY}
 * ${TIME}
 */
public class Main {
    public static void main(String[] args) {
         boolean b=validateStackSequences(new int[]{1,2,3,4,5},new int[]{4,3,5,1,2});
        System.out.println(b);
    }
    public static boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> st=new Stack<>();
        int k=0;
        for (int i = 0; i < pushed.length; i++) {
            int tmp=pushed[i];
            st.add(tmp);
            while (!st.isEmpty()&& st.peek()==popped[k]){
                st.pop();
                k++;

            }
        }
        if(st.isEmpty()){
            return true;
        }
        return false;
    }
}